package com.four.peoplemanage.excontracts.dao;

import com.four.peoplemanage.excontracts.entity.Excontracts;
import com.four.peoplemanage.overtime.entity.Overtime;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ExcontractsDao {
    //新增外聘合同
    @Insert("insert into excontracts (external_id,name,contract_number,identity,phonenumber,zip,newrenewal,resident_address,place_domicile,correspondence_address,post,type_contract,contract_begintime,contract_endtime,tryouttime,namecard)"+
            "values (#{external_id},#{name},#{contract_number},#{identity},#{phonenumber},#{zip},#{newrenewal},#{resident_address},#{place_domicile},#{correspondence_address},#{post},#{type_contract},#{contract_begintime},#{contract_endtime},#{tryouttime},#{namecard})")
    public int addExcontracts(Excontracts excontracts);
    //查看分页
    @Select("<script>" +
            "SELECT * FROM excontracts" +
            "  <where>" +
            "    <if test=\"name != null\">" +
            " <bind name=\"Key\" value=\"'%'+name+'%'\"/>" +
            "        name like #{Key} " +
            "    </if>" +
            "    <if test=\" post != null\">" +
            "       and post = #{post} " +
            "    </if>" +
            "    <if test=\" type_contract != null\">" +
            "       and type_contract = #{type_contract} " +
            "    </if>" +
            "  </where>" +
            "limit #{start}, #{size}" +
            "</script>")
    public List<Excontracts> getExcontracts(int start, int size, String name, String post,
                                         String type_contract);

    @Select("<script>" +
            "select count(*) from excontracts" +
            "  <where>" +
            "    <if test=\"name != null\">" +
            " <bind name=\"Key\" value=\"'%'+name+'%'\"/>" +
            "        name like #{Key} " +
            "    </if>" +
            "    <if test=\" post != null\">" +
            "       and post = #{post} " +
            "    </if>" +
            "    <if test=\" type_contract != null\">" +
            "       and type_contract = #{type_contract} " +
            "    </if>" +
            "  </where>" +
            "</script>")
    public  int countExcontracts(String name, String post,
                              String type_contract);

}
